home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- *
- * Module: main.c
- *
- * Purpose: Macintosh flow control
- *
- * Description: This module contains all the Macintosh flow control
- * for the ISO9660 program.
- *
- * Copyright © 1990 Apple Computer, Inc. All rights reserved.
- *
- ************************************************************************/
- #include <QuickDraw.h>
- #include <MenuMgr.h>
- #include <MemoryMgr.h>
- #include <EventMgr.h>
- #include <WindowMgr.h>
- #include <DeskMgr.h>
- #include <DialogMgr.h>
- #include <ToolboxUtil.h>
-
- #include <stdio.h>
- #include "HighSierra.h"
- #include "BuildISO.h"
- #include "DialogUtils.h"
-
- Str255 drvName = "\p.Sony"; /* name of the device driver for isoOpen() */
-
- enum {
- AppleID = 128,
- FileID,
- EditID
- };
-
- enum {
- AppleM = 1,
- FileM,
- EditM
- };
-
- #define PROMPTID 258
-
- #define HELP 1
- #define CREATEFILES 2
- #define QUIT 4
-
- #define MENUCOUNT 3
-
- MenuHandle myMenus[MENUCOUNT];
- Boolean quitProgram;
- EventRecord myEvent;
- WindowPtr whichWindow;
-
- short refNum;
- short driveNumber = 0;
-
- static void DoDisk(long);
- static void InitializeVolume(void);
-
- void SetUpMenus(void);
- void DoAbout(void);
- void DoCommand(long);
- void Leave(void);
- void HandleEvent(EventRecord *);
- void main(void);
-
-
- /************************************************************************
- *
- * Function: SetUpMenus
- *
- * Purpose: initialize menus
- *
- * Returns: nothing
- *
- * Side Effects: standard apple menus are set up
- *
- * Description: loop through MENUCOUNT times, inserting the menu
- * we got using GetMenu. Draw the menu bar.
- *
- ************************************************************************/
- void
- SetUpMenus()
- {
- int i;
-
- myMenus[AppleM] = GetMenu(AppleID);
- AddResMenu(myMenus[AppleM], 'DRVR'); /* add desk accessories */
- myMenus[FileM] = GetMenu(FileID);
- myMenus[EditM] = GetMenu(EditID); /* only used by desk access. */
-
- for (i = 1; i <= MENUCOUNT; i++)
- InsertMenu(myMenus[i], 0); /*install at end of Menu Bar */
-
- /* disable creating files until we initialize a floppy */
- /***TO DO*** DisableItem(myMenus[FileM], CREATEFILES); */
- DrawMenuBar();
- }
-
-
- /************************************************************************
- *
- * Function: DoAbout
- *
- * Purpose: give ownership & copyright information
- *
- * Returns: nothing
- *
- * Side Effects: nothing
- *
- * Description: put up an alert, telling about us.
- *
- ************************************************************************/
- void
- DoAbout()
- {
- Alert(DU_CenterALRT(128), 0L);
- }
-
-
-
- /************************************************************************
- *
- * Function: DoCommand
- *
- * Purpose: Handle command or command key equivalent
- *
- * Returns: void
- *
- * Side Effects: whatever it executes may have a side effect.
- *
- * Description: Look at the menu selected and the item of that menu,
- * and do a case statement on the item. Execute the
- * appropriate item.
- *
- ************************************************************************/
- void
- DoCommand(mResult)
- long mResult;
- {
- int theItem;
- int theMenu;
- Str255 name;
- GrafPtr savePort;
-
- theItem = LoWord(mResult);
- theMenu = HiWord(mResult);
-
- switch (theMenu) {
- case AppleID:
- if (theItem == 1) /* tell about the program */
- DoAbout();
- else {
- GetPort(&savePort);
- GetItem(myMenus[AppleM], theItem, name);
- OpenDeskAcc(name);
- SetPort(savePort);
- }
- break;
- case FileID:
- switch (theItem)
- {
- case HELP:
- Help();
- break;
- case CREATEFILES:
- CreatePathTable(refNum);
- CreateFiles(refNum);
- /* DisableItem(myMenus[FileM], CREATEFILES); */
- break;
- case QUIT:
- quitProgram = true;
- break;
- }
- case EditID:
- SystemEdit(theItem - 1);
- break;
- }
- HiliteMenu(0);
- }
-
-
-
- /************************************************************************
- *
- * Function: DoDisk
- *
- * Purpose: Handle disk inserted events
- *
- * Returns: nothing
- *
- * Side Effects: may initialize a disk
- *
- * Description: check the return code from the mount attempt (the
- * high word of the event message coming in.) If the
- * mount failed, go ahead and initialize it using DIFormat.
- * This gets the basic format information, but no file
- * system information.
- *
- ************************************************************************/
- static void
- DoDisk(message)
- long message;
- {
- OSErr result;
- CursHandle cursor;
-
- driveNumber = LoWord(message);
- result = HiWord(message);
-
- /* if a mount failed (e.g. blank floppy) then we can format the floppy
- ** without doing anything. If the mount succeeded, the floppy was in
- ** some format that the Mac recognized. Unmount the volume and flush
- ** it out of the mac without ejecting it, and *then* format it.
- */
- if (result == noErr)
- {
- if (AskDestroyDisk(driveNumber) == true)
- result = UnmountVol(NULL, driveNumber);
- else
- {
- UnmountVol(NULL, driveNumber);
- Eject(NULL, driveNumber);
- return; /* get rid of that volume and return now! */
- }
- }
-
- cursor = GetCursor(watchCursor);
- if (!cursor)
- SetCursor(*cursor);
- result = DIFormat(driveNumber);
- InitializeVolume();
- EnableItem(myMenus[FileM], CREATEFILES);
- SetCursor(&arrow);
-
- if (result != noErr)
- ErrorMsg("Can't format volume! (result = %d)", result);
- }
-
-
- /************************************************************************
- *
- * Function: Leave
- *
- * Purpose: allow program to recover from some bombs
- *
- * Returns: void
- *
- * Side Effects: does an exit to shell
- *
- * Description: If you are running without a debugger and get a bomb,
- * this procedure enables the "resume" button of the
- * DSAlert bomb box. It may even do the correct thing,
- * under the circumstances.
- *
- ************************************************************************/
- void
- Leave()
- {
- ExitToShell();
- }
-
-
- void
- HandleEvent(myEvent)
- EventRecord *myEvent;
- {
- DialogPtr dPtr;
- short itemHit;
-
- switch (myEvent->what) {
- case mouseDown:
- switch (FindWindow(myEvent->where, &whichWindow)) {
- case inSysWindow:
- SystemClick(myEvent, whichWindow);
- break;
- case inMenuBar:
- DoCommand(MenuSelect(myEvent->where));
- break;
- } /* end MouseDown */
- break;
- case keyDown:
- case autoKey:
- if ((myEvent->modifiers & cmdKey) != 0)
- DoCommand (MenuKey ((char) (myEvent->message & 0xFF)));
- break;
- case diskEvt:
- DoDisk(myEvent->message);
- break;
- case updateEvt: /* These can only happen to our dialogs */
- case activateEvt:
- DialogSelect(myEvent, &dPtr, &itemHit);
- } /* end myEvent.what */
- }
-
- /************************************************************************
- *
- * Function: main
- *
- * Purpose: control this puppy
- *
- * Returns: none
- *
- * Side Effects: none inherient in this routine. Routines called
- * from here do all the work.
- *
- * Description: Do standard Macintosh initialization.
- *
- ************************************************************************/
- void
- main()
- {
- OSErr result;
- DialogPtr dPtr;
- short itemHit;
-
-
- InitGraf((Ptr)&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs((ProcPtr)Leave);
- InitCursor();
- MoreMasters();
-
- SetUpMenus();
-
- refNum = 0;
- result = isoOpen(drvName, &refNum);
- if (result != noErr)
- {
- ErrorMsg("isoOpen failed with code %d (0x%x)", result, result);
- return;
- }
-
- quitProgram = false;
-
- dPtr = GetNewDialog(DU_CenterDLOG(PROMPTID), (DialogPeek)0L, (WindowPtr)-1L);
- do {
- SystemTask();
- if (GetNextEvent(everyEvent, &myEvent)) {
- HandleEvent(&myEvent);
- } /* end if */
- } while (quitProgram == false);
- DisposDialog(dPtr);
-
- if (driveNumber != 0)
- {
- result = Eject(NULL, driveNumber);
- if (result != noErr)
- ErrorMsg("can't eject floppy! (%d)", result);
- }
- }
-
-
- /************************************************************************
- *
- * Function: InitializeVolume
- *
- * Purpose: initialize volume
- *
- * Returns: nothing
- *
- * Side Effects: destroys volume and create PVD and VDT instead
- *
- * Description:
- *
- ************************************************************************/
- static void
- InitializeVolume()
- {
- OSErr result;
-
- result = ZeroDisk(refNum);
- if (result == noErr)
- {
- result = CreatePVD(refNum);
- if (result == noErr)
- result = CreateVDT(refNum);
- }
- if (result != noErr)
- ErrorMsg("Couldn't initialize volume");
- }
-
-